Integrating vale with github actions
Automate documentation linting by integrating Vale into CI/CD workflows using GitHub Actions.
π Setting up gitHub actionsβ
Create a GitHub Actions workflow:
- Navigate to your repositoryβs root.
- Create a
.github/workflows/
directory if it doesn't exist. - Add a
vale-linter.yml
file inside it.
Use the official Vale GitHub Action:
π GitHub actions workflowβ
name: Documentation Linting
on:
push: # Run on every push to main
branches:
- main
pull_request: # Run on all pull requests
branches:
- "*"
jobs:
lint:
name: Run Vale Linter
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
# Install external parsers if needed
# For AsciiDoc users:
- name: Install Asciidoctor
run: sudo apt-get install -y asciidoctor
# For reStructuredText users:
- name: Install docutils
run: sudo apt-get install -y docutils
- name: Run Vale Linter
uses: errata-ai/vale-action@v2.1.1
with:
version: 2.17.0
files: .
reporter: github-pr-check # Options: github-pr-check, github-pr-review, github-check
fail_on_error: true
filter_mode: nofilter # Options: added, diff_context, file, nofilter
vale_flags: "--glob=*.md"
env:
# Required, set by GitHub actions automatically:
#GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
#REVIEWDOG_GITHUB_API_TOKEN: ${{secrets.GITHUB_TOKEN}}
After making these changes, run the following commands:
πΉ CI/CD Featuresβ
β
Runs on Every Push & Pull Request: Automatically triggers on main
and PRs.
β
Flags Documentation Issues in PRs: Prevents issues before merging.
β
Supports Additional Parsers: Installs Asciidoctor and docutils as needed.
β
Fails PR on Critical Errors (fail_on_error: true
).
git add .
git commit -m "Apply documentation updates"
git pushCheck the Actions tab in your repository to view the workflow status.
Click on theΒ
changes
Β button and click on the jobΒprose
π§ Customization optionsβ
-
Lint only specific directories (e.g.,
docs/
):with:
files: docs/ -
Use PR review comments instead of PR checks:
with:
reporter: github-pr-review -
Exclude specific files using glob patterns:
with:
vale_flags: "--glob=!docs/excluded.md"
π Recommended repository structureβ
.github/
βββ styles/
β βββ vocab.txt # Custom terminology rules for consistent language
βββ workflows/
βββ vale-linter.yml # GitHub Actions workflow for automated linting
.vale.ini # Vale configuration file for linting rules
docs/
βββ example.md # Documentation file with examples and guidelines
Explanation of structure:
.github/
: Contains GitHub-specific files.
-
styles/
: Holds custom terminology rules to ensure consistent language across the project. -
workflows/
: Contains the workflow configuration for GitHub Actions, which automates the linting process using Vale. -
.vale.ini
: The main configuration file for Vale, defining the linting rules and settings for the project. -
docs/
: Directory for project documentation.
π οΈ Troubleshooting vale issuesβ
β 1οΈβ£ Missing styles?β
Run:
vale sync
Ensure the styles/
directory contains required styles (Microsoft
, write-good
, etc.).
β 2οΈβ£ .vale.ini
Parsing errors?β
Check for:
β
Proper formatting of BasedOnStyles
β
No missing commas or syntax errors
β
Valid IgnorePatterns
β 3οΈβ£ Excluding unwanted files?β
Modify your .vale.ini
:
ignore = node_modules, vendor, dist, .git, .github
This prevents Vale from linting unnecessary directories.
π Final thoughtsβ
Integrating Vale with GitHub Actions is a powerful way for technical writers, developers, and documentation teams to ensure consistent, professional, and error-free documentation.
It works for both local linting and CI/CD automation, helping you maintain high documentation standards effortlessly.